package initialize

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"nnxy-search-api/search-user-api/api"
	"nnxy-search-api/search-user-api/middleware"
	"nnxy-search-api/search-user-api/route"
)

// Routers 初始化路由
func Routers() *gin.Engine {
	Router := gin.Default()
	Router.Use(middleware.Cors()) // 跨域请求
	Router.GET("/health", func(context *gin.Context) {
		context.JSON(http.StatusOK, gin.H{
			"code":    200,
			"success": true,
		})
	})
	ApiGroup := Router.Group("/u/v1")

	route.InitUserRoute(ApiGroup)
	route.InitCommonRoute(ApiGroup)

	// 后台用户
	Router.POST("/admin", api.AdminLogin) // 后台登录
	AdminGroup := Router.Group("/admin")
	route.InitAdminRoute(AdminGroup)
	return Router
}
